package com.nnfe.fyd.utils;

import android.content.Context;
import android.widget.Toast;

import com.nnfe.fyd.App;


/**
 * 土司工具类
 */
public class ToastUtil {

    private static Context mContext = App.getContext();
    public static Toast mToast;

    /**
     * 立即连续弹短吐司
     *
     * @param mContext
     * @param msg
     */
    public static void showShortToast(final Context mContext, final String msg) {
        CommonUtil.runOnUIThread(new Runnable() {
            @Override
            public void run() {
                if (mToast == null) {
                    mToast = Toast.makeText(mContext, "", Toast.LENGTH_SHORT);
                }
                mToast.setText(msg);
                mToast.show();
            }
        });
    }

    /**
     * 立即连续弹长吐司
     *
     * @param mContext
     * @param msg
     */
    public static void showLongToast(final Context mContext, final String msg) {
        CommonUtil.runOnUIThread(new Runnable() {
            @Override
            public void run() {
                if (mToast == null) {
                    mToast = Toast.makeText(mContext, "", Toast.LENGTH_LONG);
                }
                mToast.setText(msg);
                mToast.show();

            }
        });
    }

    /**
     * 短时间内连击弹出退出的toast
     *
     * @param msg
     */
    public void showSystemShortToast(final Context mContext, final String msg) {
        if (!OnClickUtil.isFastDoubleClick(2000)) {
            CommonUtil.runOnUIThread(new Runnable() {
                @Override
                public void run() {
                    if (mToast == null) {
                        mToast = Toast.makeText(mContext, "", Toast.LENGTH_SHORT);
                    }
                    mToast.setText(msg);
                    mToast.show();
                }
            });
        }
    }

    public static void showToast(final String msg){
        CommonUtil.runOnUIThread(new Runnable() {
            @Override
            public void run() {
                if (mToast == null) {
                    mToast = Toast.makeText(mContext, "", Toast.LENGTH_LONG);
                }
                mToast.setText(msg);
                mToast.show();
            }
        });
    }
}
